// components/FamilyTest.tsx
import React, { useEffect } from 'react';
import { View, Text, Button } from 'react-native';
import { createFamily, generateInviteCode, joinFamily, getFamilyMembers, leaveFamily } from '../../api/family';

const FamilyTest = () => {
  const testCreateFamily = async () => {
    try {
      const response = await createFamily({
        name: 'Test Family'
      });
      console.log('Create family response:', response.data);
    } catch (error) {
      console.error('Create family error:', error);
    }
  };

  const testGenerateInviteCode = async () => {
    try {
      const response = await generateInviteCode();
      console.log('Generate invite code response:', response.data);
    } catch (error) {
      console.error('Generate invite code error:', error);
    }
  };

  const testJoinFamily = async () => {
    try {
      const response = await joinFamily({
        code: '019d758d-938d-450d-aba4-944b3c2b5787'
      });
      console.log('Join family response:', response.data);
    } catch (error) {
      console.error('Join family error:', error);
    }
  };

  const testGetFamilyMembers = async () => {
    try {
      const response = await getFamilyMembers();
      console.log('Get family members response:', response.data);
    } catch (error) {
      console.error('Get family members error:', error);
    }
  };

  const testLeaveFamily = async () => {
    try {
      const response = await leaveFamily();
      console.log('Leave family response:', response.data);
    } catch (error) {
      console.error('Leave family error:', error);
    }
  };

  useEffect(() => {
    testCreateFamily();
    testGenerateInviteCode();
    testJoinFamily();
    testGetFamilyMembers();
    testLeaveFamily();
  }, []);

  return (
    <View>
      <Text>Family API Test</Text>
      <Button title="Create Family" onPress={testCreateFamily} />
      <Button title="Generate Invite Code" onPress={testGenerateInviteCode} />
      <Button title="Join Family" onPress={testJoinFamily} />
      <Button title="Get Family Members" onPress={testGetFamilyMembers} />
      <Button title="Leave Family" onPress={testLeaveFamily} />
    </View>
  );
};

export default FamilyTest;